<?php

namespace Wx\Controller;
use Think\Controller;

class MyCollectController extends CommonController{

    // 个人中心-收藏列表
    public function index(){
        $map['c.u_id'] = session('u_id');
        $list = M('shop_spellgroup_collection')->table(C('DB_PREFIX') . "shop_spellgroup_collection as c")
            ->join(C('DB_PREFIX') . "shop_spellgroup as g ON g.id = c.group_id")
            ->field('c.*,g.id as g_id,g.title,g.u_id as store_boss_id,g.s_id,g.type,g.h_imgs,g.state')
            ->where($map)
            ->order('addtime desc')
            ->select();
        foreach ($list as $k => $v) {// 查询拼团商品信息，拼团的商家或者农户的信息
            // 处理主图
            $list[$k]['h_imgs'] = isMorePic($v['h_imgs']);
            if($list[$k]['type']==1){// 如果是商家拼团
                $list[$k]['storename'] = M('shop_store')->where('id = '.$v['s_id'])->getField('storename');
                $list[$k]['type'] = '门店';
            }else{
                $list[$k]['storename'] = M('member_farmers')->where('u_id = '.$v['store_boss_id'])->getField('village');
                $list[$k]['type'] = '乡村';
            }
            // 查询商家或农户的姓名与头像
            $list[$k]['m_info'] = getMember($v['store_boss_id'], 'nickname,avatar');
        }// end foreach
//        dump($list);
        $this->assign('list', $list);
        $this->display('collection');
    }// end fun index()


}